package com.ruibang.glass.quality.config;

import com.ruibang.glass.common.constants.RedisKey;
import com.ruibang.glass.quality.component.subscriber.BcStationHqDetailMsgReceiver;
import com.ruibang.glass.quality.component.subscriber.GlassBindTestMsgReceiver;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-05-09  14:37
 * @Description: TODO:同步本地缓存
 * @Version: 1.0
 */
@Configuration
public class RedisSubscriberConfig {


    /**
     * @Description: 容器配置
     * @version v1.0
     * @author songJinKang
     * @date 2024-05-09 14:44
     */
    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory factory,
                                                   @Qualifier("bcStationHqDetailListenerAdapter") MessageListenerAdapter bcStationHqDetailAdapter,
                                                   @Qualifier("glassBindTestListenerAdapter") MessageListenerAdapter glassBindTestAdapter) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(factory);
        container.addMessageListener(glassBindTestAdapter, new PatternTopic(RedisKey.REDIS_GLASS_BIND_TEST_TOPIC));
        container.addMessageListener(bcStationHqDetailAdapter, new PatternTopic(RedisKey.REDIS_BC_STATION_HQ_DETAIL_TOPIC));
        return container;
    }


    /**
     * @Description: bc_station_hq_detail订阅配置
     * @version v1.0
     * @author songJinKang
     * @date 2024-05-09 14:42
     */
    @Bean
    public MessageListenerAdapter bcStationHqDetailListenerAdapter(BcStationHqDetailMsgReceiver receiver) {
        return new MessageListenerAdapter(receiver, "receiveMessage");
    }


    /**
     * @Description: glass_bind_test订阅配置
     * @version v1.0
     * @author songJinKang
     * @date 2024-05-09 14:42
     */
    @Bean
    public MessageListenerAdapter glassBindTestListenerAdapter(GlassBindTestMsgReceiver receiver) {
        return new MessageListenerAdapter(receiver, "receiveMessage");
    }


}
